<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="楼层数" prop="storeyName">
        <el-input
          v-model="queryParams.storeyName"
          placeholder="请输入楼层数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="区名称" prop="regionName">
        <el-input
          v-model="queryParams.regionName"
          placeholder="请输入区名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="楼层id也就是本表的主键id" prop="regionid">
        <el-input
          v-model="queryParams.regionid"
          placeholder="请输入楼层id也就是本表的主键id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:regioninfo:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:regioninfo:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:regioninfo:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:regioninfo:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-container style="height: 500px; border: 1px solid #eee">
      <el-aside width="200px" style="background-color: rgb(238, 241, 246)">
        <el-menu :default-openeds="['1', '2']">
          <el-submenu index="1">
            <template slot="title"
              ><i class="el-icon-message"></i>楼层信息</template
            >
            <el-submenu index="1-1">
              <template slot="title">楼层</template>
              <el-menu-item index="1-1-1" @click="getList(1,null)"
                >-1层</el-menu-item
              >
              <el-menu-item index="1-1-2" @click="getList(2,null)"
                >-2层</el-menu-item
              >
            </el-submenu>
            <el-submenu index="1-2">
              <template slot="title">区域信息</template>
              <el-menu-item index="1-2-1" @click="getList(null,'A区')">A区</el-menu-item>
              <el-menu-item index="1-2-2" @click="getList(null,'B区')">B区</el-menu-item>
              <el-menu-item index="1-2-3" @click="getList(null,'C区')">C区</el-menu-item>
              <el-menu-item index="1-2-4" @click="getList(null,'D区')">D区</el-menu-item>
            </el-submenu>
          </el-submenu>
        </el-menu>
      </el-aside>

      <el-table
        v-loading="loading"
        :data="regioninfoList"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55" align="center" />
        <!-- <el-table-column label="区域主键ID" align="center" prop="regionId" /> -->
        <el-table-column label="楼层数" align="center" prop="storeyName" />
        <el-table-column label="区名称" align="center" prop="regionName" />
        <el-table-column label="车位数量" align="center" prop="spacequantity" />
        <el-table-column
          label="固定车位数量"
          align="center"
          prop="purchasedQuantity"
        />
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['system:regioninfo:edit']"
              >修改</el-button
            >
            <!-- <el-button @click="indexList(scope.row.regionId)"
              >区域详细车位</el-button
            > -->
            <el-button @click="indexList(scope.row.regionId,scope.row.storeyName,scope.row.regionName)"
             type="primary" style="margin-left: 16px;" 
             v-hasPermi="['system:regioninfo:remove']">
              区域详细车位
</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['system:regioninfo:remove']"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </el-container>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改区域管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="楼层数" prop="storeyName">
          <el-input v-model="form.storeyName" placeholder="请输入楼层数" />
        </el-form-item>
        <el-form-item label="区名称" prop="regionName">
          <el-input v-model="form.regionName" placeholder="请输入区名称" />
        </el-form-item>
        <!-- <el-form-item label="楼层id也就是本表的主键id" prop="regionid">
          <el-input v-model="form.regionid" placeholder="请输入楼层id也就是本表的主键id" />
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-drawer
  :title="title"
  :visible.sync="drawer"
  :direction="direction"
  :before-close="handleClose">
  <span    v-loading="loading"
        :data="spacequantityList" >
    <span v-for="(item, index) in spacequantityList.rows
" :key="index"  >
      <button class="ellipse-border" :style="{ backgroundColor: getBackgroundColor(item.purchasedds)}" >{{item.regionidds}}<div></div>{{ item.quantityname}}<div></div>{{item.purchasedds}}<div></div>{{item.typeNameds}}</button>
      <div v-if="(index + 1) % 5 === 0"/> 
    </span>
    <pagination
      v-show="tot > 0" 
      :total="tot"
      :page.sync="queryParams.queryParams2[0].pageNum"
      :limit.sync="queryParams.queryParams2[0].pageSize"
      @pagination="indexList"
    />
  </span>
</el-drawer>
  </div>



</template>

<style>
.el-header {
  background-color: #b3c0d1;
  color: #333;
  line-height: 60px;
}

.el-aside {
  color: #333;
}

.ellipse-border {  
/* 设定固定宽度和高度 */  
width: 200px; /* 例如宽度为200px */  
  height: 100px; /* 例如高度为100px，形成椭圆形 */  
  border: 2px solid #333; /* 设置边框颜色和粗细 */  
  border-radius: 50%; /* 设置为50%以创建椭圆形边框 */  
  background-color: transparent; /* 确保没有背景颜色 */  
  /* 可以在这里添加其他的样式属性，比如margin, padding等 */  
}   
</style>
<script>
import {
  listRegioninfo,
  getRegioninfo,
  delRegioninfo,
  addRegioninfo,
  updateRegioninfo,
  getSpecialregion,
} from "@/api/system/regioninfo";
// import{getSpecialregion}from "@/api/system/specialregion";
import axios from "axios";
export default {
  name: "Regioninfo",
  data() {
    return {
      drawer: false,
        direction: 'btt',
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      tot: 0,
      // 区域管理表格数据
      regioninfoList: [],
    spacequantityList: [],
    queryParams2:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      iame: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        storeyName: null,
        regionName: null,
        regionid: null,
        spacequantity: null,
        purchasedQuantity: null,
        queryParams2: [{
    pageNum: 1,
        pageSize: 10,
        regionid: 3,
        typeNameds: null,
        quantityname: null,
        typeNameds: null,
        purchasedds: null,
        title:null,
      }],
      },
      regionId: "",
      // 表单参数
      form: {},
      
      forms: {},
      // 表单校验
      rules: {},
      rule: {},
    };
  },

  query: {
        pageNum: 1,
        pageSize: 10,
        regionid: 3,
        typeNameds: null,
        quantityname: null,
        typeNameds: null,
        purchasedds: null,
      },
  created() {
    this.getList();
  },
  methods: {
    handleClose(done) {
            done();
      }
    ,
    /** 查询区域管理列表 */
    getList(louc, quy) {
      this.loading = true;
      if (louc != null && louc != 0) {
        this.queryParams.regionid = louc;
        this.queryParams.regionName=null;
      }
      if (quy != null && quy != "") {
        this.queryParams.regionid=null;
        this.queryParams.regionName = quy;
      }
      listRegioninfo(this.queryParams).then((response) => {
        this.regioninfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        regionId: null,
        storeyName: null,
        regionName: null,
        region_id: null,
        spacequantity: null,
        purchasedQuantity: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.regionId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加区域管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const regionId = row.regionId || this.ids;
      getRegioninfo(regionId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改区域管理";
      });
    },
    indexList(region,louc,quyu) {
        this.drawer=true;
        if(quyu!=null&&louc!=null){
          this.queryParams.queryParams2[0].title=louc+'层的'+quyu
        }
       if(region!=null){
        this.queryParams.queryParams2[0].regionid=region
       }
        this.title=this.queryParams.queryParams2[0].title;
        // this.query.regionid=region
        getSpecialregion(this.queryParams.queryParams2[0]).then((response) => {
        this.spacequantityList = response;
        console.log(this.spacequantityList);
        this.tot = response.total;
        this.loading = false;
      });
     
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.regionId != null) {
            updateRegioninfo(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRegioninfo(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    getBackgroundColor(id) {  
      // 根据 id 判断背景颜色  
      if (id === '已购买') {  
        return 'red'; // 如果 id 是 1，返回红色  
      }  
      // 可以添加更多条件或默认颜色  
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const regionIds = row.regionId || this.ids;
      this.$modal
        .confirm('是否确认删除区域管理编号为"' + regionIds + '"的数据项？')
        .then(function () {
          return delRegioninfo(regionIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/regioninfo/export",
        {
          ...this.queryParams,
        },
        `regioninfo_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
